package converters;

import java.util.Iterator;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import modelo.Combobebidaxsalon;
import modelo.CombobebidaxsalonId;
import services.ComboBebidaXSalonService;

@FacesConverter("comboBebidaXSalonConverter")
public class ComboBebidaXSalonConverter implements Converter {
	
	public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
        if(value != null && value.trim().length() > 0) {
        	ComboBebidaXSalonService service = (ComboBebidaXSalonService) fc.getExternalContext().getApplicationMap().get("comboBebidaXSalonService");
           // return service.obtenerUnidadMedidaById(Integer.parseInt(value));
            Iterator<Combobebidaxsalon> i=service.getListacombobebidaxsalon().iterator();
            while (i.hasNext()) {
            	Combobebidaxsalon cbxs = (Combobebidaxsalon) i.next();
				if(cbxs.getId() == Combobebidaxsalon(value))//ver despues
					return cbxs;
			}
            return null;
        }
        else {
            return null;
        }
    }
 
    private CombobebidaxsalonId Combobebidaxsalon(String value) {
		// TODO Auto-generated method stub
		return null;
	}

	public String getAsString(FacesContext fc, UIComponent uic, Object object) {
        if(object != null) {
        	return String.valueOf(((Combobebidaxsalon) object).getId());
        }
        else {
            return null;
        }
    }  

}